package com.woniu.rabbit.topic_model.excange_queue_conf;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class PublishExchangeAndQueueConfig {
    public static final String EXCHANGE_NAME = "publish.exchange";
    public static final String QUEUE_NAME01 = "queue.publish01";
    public static final String QUEUE_NAME02 = "queue.publish02";
    public static final String QUEUE_NAME03 = "queue.publish03";

    /**
     * 创建广播交换机
     * */
    @Bean
    public FanoutExchange fanoutExchange(){
        log.info("创建交换机：{}",EXCHANGE_NAME);
        return new FanoutExchange(EXCHANGE_NAME);
    }

    /**
     * 创建 1号队列
     * */
    @Bean
    public Queue fanoutQueue01(){
        log.info("创建队列：{}",QUEUE_NAME01);
        return new Queue(QUEUE_NAME01,true); // 指定队列名称,持久化
    }
    /**
     * 创建 2号队列
     * */
    @Bean
    public Queue fanoutQueue02(){
        log.info("创建队列：{}",QUEUE_NAME02);
        return new Queue(QUEUE_NAME02,true);
    }
    /**
     * 创建 3号队列
     * */
    @Bean
    public Queue fanoutQueue03(){
        log.info("创建队列：{}",QUEUE_NAME03);
        return new Queue(QUEUE_NAME03,true);
    }

    /**
     * 将队列绑定到交换机
     * */
    @Bean
    public Binding topicBinding01(FanoutExchange fanoutExchange,Queue fanoutQueue01){
        // `*`：匹配一个单词（例如 `key.*` 匹配 `key.a`、`key.b`）。
        return BindingBuilder.bind(fanoutQueue01).to(fanoutExchange);
    }

    @Bean
    public Binding topicBinding02(FanoutExchange fanoutExchange,Queue fanoutQueue02){
        // `#`：匹配零个或多个单词（例如 `key.#` 匹配 `key.a`、`key.a.b.c`）
        return BindingBuilder.bind(fanoutQueue02).to(fanoutExchange);
    }

}
